var _tools = require("../../../utils/tools.js"), _tools2 = _interopRequireDefault(_tools);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var that, app = getApp();

function e(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var i = e(require("./modules/base-canvas-palette.js")), n = e(require("../../../utils/wx-promisify/wx-promisify.js")), d = e(require("./modules/handle-create-img.js")), h = ((0, 
n.default)(wx.getSetting), 0), p = 0;

Page({
    data: {
        height: 2 * app.globalData.height + 20,
        loading: !1,
        shareshow: !1,
        nav: {
            title: "主页",
            showHome: !1,
            isHomePage: !0
        },
        id: 0,
        imageStyle: "",
        img_height: 0,
        sIndex: 0,
        poster_images: [],
        creat_img: !1
    },
    onReady: function() {
        wx.setNavigationBarColor({
            frontColor: "#000000",
            backgroundColor: "#000000"
        });
        var t = {
            action: "poster",
            contr: "luck",
            token: wx.getStorageSync("token"),
            id: this.data.id
        };
        _tools2.default.request(t, function(t) {
            that.setData(t.info), that.generatePoster();
        }), this.data.img_height = getApp().globalData.systemInfo.screenHeight - 180;
    },
    onLoad: function(t) {
        (that = this).data.id = t.id;
    },
    onShow: function() {},
    chooseTheme: function(t) {
        this.setData({
            sIndex: t.currentTarget.dataset.index
        }), this.generatePoster();
    },
    generatePoster: function() {
        if (this.data.poster_images[this.data.sIndex]) this.setData({
            poster_img: this.data.poster_images[this.data.sIndex]
        }); else {
            var t = this.data.bg[this.data.sIndex].bg, e = this.data.bg[this.data.sIndex].color, a = 1100 + 330 * (this.data.luck_info.length - 1), i = 800 + 330 * (this.data.luck_info.length - 1), s = Math.ceil(this.data.luck.lottery_explain.length / 23);
            console.log(a);
            var r = 0;
            0 < s - 2 && (r = 25 * (s - 2)), a += r, i += r, this.setData({
                z_h: a,
                creat_img: !0
            });
            var o = [ {
                type: "image",
                url: t,
                css: {
                    top: "0rpx",
                    left: "0rpx",
                    width: "680rpx",
                    height: a + "rpx",
                    mode: "scaleToFill"
                }
            }, {
                type: "image",
                url: this.data.head,
                css: {
                    top: "50rpx",
                    left: "297rpx",
                    width: "96rpx",
                    height: "96rpx",
                    borderRadius: "100px",
                    borderWidth: "1px",
                    borderColor: "#ffffff"
                }
            }, {
                type: "text",
                text: this.data.member.nickname,
                css: Object.assign({
                    top: "165rpx",
                    left: "339rpx",
                    align: "center",
                    maxLines: 1,
                    width: "300rpx",
                    color: e,
                    fontSize: "22rpx",
                    fontWeight: "bold"
                })
            }, {
                type: "text",
                text: "邀请您来参加抽奖",
                css: Object.assign({
                    top: "210rpx",
                    left: "339rpx",
                    align: "center",
                    maxLines: 1,
                    width: "300rpx",
                    color: e,
                    fontSize: "30rpx",
                    fontWeight: "bold"
                })
            }, {
                type: "image",
                url: this.data.images.white,
                css: {
                    top: "260rpx",
                    left: "15rpx",
                    width: "640rpx",
                    height: i + "rpx",
                    mode: "scaleToFill"
                }
            } ], n = 295, h = 560;
            for (var p in this.data.luck_info) {
                n = 295 + 330 * p, h = 560 + 330 * p;
                var l = {
                    type: "image",
                    url: this.data.luck_info[p].image,
                    css: {
                        top: n + "rpx",
                        left: "40rpx",
                        width: "600rpx",
                        height: "250rpx",
                        mode: "scaleToFill"
                    }
                };
                o.push(l);
                var g = {
                    type: "text",
                    text: "奖品：" + this.data.luck_info[p].name + "×" + this.data.luck_info[p].number,
                    css: {
                        top: h + "rpx",
                        left: "40rpx",
                        align: "left",
                        maxLines: 1,
                        width: "490rpx",
                        color: "#333",
                        fontSize: "28rpx",
                        fontWeight: "bold"
                    }
                };
                o.push(g);
            }
            var x = {
                type: "text",
                text: this.data.luck.lottery_font,
                css: {
                    top: h + 50 + "rpx",
                    left: "40rpx",
                    align: "left",
                    maxLines: 1,
                    width: "490rpx",
                    color: "#C0C0C0",
                    fontSize: "25rpx",
                    fontWeight: "bold"
                }
            };
            o.push(x);
            var c = {
                type: "image",
                url: this.data.code,
                css: {
                    top: h + 130 + "rpx",
                    left: "253rpx",
                    width: "186rpx",
                    height: "186rpx"
                }
            };
            o.push(c);
            var f = {
                type: "text",
                text: "长按识别二维码, 参与抽奖",
                css: Object.assign({
                    top: h + 330 + "rpx",
                    left: "339rpx",
                    align: "center",
                    maxLines: 1,
                    width: "600rpx",
                    color: "#C0C0C0",
                    fontSize: "25rpx",
                    fontWeight: "bold"
                })
            };
            o.push(f);
            var u = {
                type: "text",
                text: "-----------------  抽奖说明  -----------------",
                css: Object.assign({
                    top: h + 380 + "rpx",
                    left: "339rpx",
                    align: "center",
                    width: "600rpx",
                    color: "#C9C9C9",
                    fontSize: "28rpx",
                    fontWeight: "bold"
                })
            };
            o.push(u);
            u = {
                type: "text",
                text: this.data.luck.lottery_explain,
                css: Object.assign({
                    top: h + 430 + "rpx",
                    maxLines: 100,
                    left: "62rpx",
                    width: "568rpx",
                    color: "#C9C9C9",
                    fontSize: "25rpx"
                })
            };
            o.push(u), this.data.poster = {
                content: o,
                z_h: a
            }, console.log(o), wx.showLoading({
                title: "正在生成海报",
                mask: !0
            }), d.default.doCreateImg(this);
            try {
                getApp().sensors.track("XMClick", {
                    ck_module: "保存海报",
                    page: "抽奖海报"
                });
            } catch (t) {}
        }
    },
    imgErr: function(t) {
        d.default.createImgFail(t);
    },
    onImgOK: function(t) {
        wx.hideLoading();
        var e = "height:" + this.data.img_height + "px";
        this.data.img_height;
        this.setData({
            poster_img: t.detail.path,
            imageStyle: e,
            creat_img: !1
        }), this.data.poster_images[this.data.sIndex] = t.detail.path;
    },
    savePoster: function() {
        wx.saveImageToPhotosAlbum({
            filePath: this.data.poster_images[this.data.sIndex],
            success: function(t) {
                wx.showToast({
                    title: "保存成功"
                });
            }
        });
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share.text,
            imageUrl: this.data.share.images,
            path: "bh_bargain/pages/index/index?parent_id=" + this.data.share.member_id
        };
    },
    previewImage: function() {
        wx.previewImage({
            current: that.data.poster_img,
            urls: [ that.data.poster_img ]
        });
    }
});